package com.springboot.uav.controller;

import com.springboot.uav.dto.AddressDto;
import com.springboot.uav.entity.Address;
import com.springboot.uav.entity.Result;
import com.springboot.uav.service.AddressService;
import com.springboot.uav.vo.AddressVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/address")
@Slf4j
@Tag(name = "地址接口", description = "地址管理相关接口")
public class AddressController {
    @Autowired
    private AddressService addressService;

    //根据id查询地址--》在新增订单按钮可以生效
    @GetMapping("/{userId}")
    @Operation(summary = "地址查询接口", description = "单击新增")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200",description = "常用地址不为空"),
            @ApiResponse(responseCode = "400",description = "常用地址为空，先新建常用地址")
    })
    public Result getAddressByUserId(@PathVariable Integer userId,@RequestParam Integer addressType) {
        return addressService.getAddressByUserId(userId,addressType);
    }

    @PostMapping("/add/pickupAddress")
    @Operation(summary = "新增取货地址接口", description = "单击新增取货地址按钮新增地址")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200",description = "新增成功"),
            @ApiResponse(responseCode = "400",description = "新增失败")
    })
    public Result addPickupAddress(@RequestBody AddressDto addressDto) {
        return addressService.addPickupAddress(addressDto);
    }

    @PostMapping("/add/deliveryAddress")
    @Operation(summary = "新增收货地址接口", description = "单击新增收货地址按钮新增地址")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200",description = "新增成功"),
            @ApiResponse(responseCode = "400",description = "新增失败")
    })
    public Result addDeliveryAddress(@RequestBody AddressDto addressDto) {
        return addressService.addDeliveryAddress(addressDto);
    }
}
